package com.example.RuanJianKeShe.Service.manager.add;

import com.alibaba.fastjson.JSON;
import com.example.RuanJianKeShe.Bean.Student;
import com.example.RuanJianKeShe.Dao.impl.StudentDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/addStudentInfo")
public class addStudentInfo extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        System.out.println(req.getParameter("msg"));
        Student student = new Student();
        student.setSname(req.getParameter("name"));
        student.setSsex(req.getParameter("sex"));
        student.setStukey("123");
        student.setSage(Integer.parseInt(req.getParameter("age")));;
        student.setTelephone(req.getParameter("telephone"));;
        student.setEmail(req.getParameter("email"));
        StudentDaoImpl studentDao = new StudentDaoImpl();
        Boolean flag = studentDao.addStudent(student);
        if (flag==true){
            String jsonString = JSON.toJSONString("success");
            resp.getWriter().write(jsonString);
        }else{
            String jsonString = JSON.toJSONString("fail");
            resp.getWriter().write(jsonString);
        }

    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
